<?php
namespace app\components;
use Yii;
use app\models\Logs;
use yii\console\Exception;

/**
 * 订单处理类
 */
class Log extends \yii\base\Widget
{
    /**
     * Starts recording a block.
     */
    public function init()
    {
		/******* init *********/
    }


	/**
	 * 日志新增
	 * @param $code    vchar
	 * @param $type    INTERGE 
	 *
	 */
	public function info($code, $oper_type, $desc ='', $params='', $type=1){//{{{

		if($code){
			$model = new Logs();
			$model->code = $code;
			$model->oper_type = $oper_type;

			if($desc){
				$model->desc = $desc;
			}

			if($params){
				$model->params = json_encode($params);
			}

			$model->type = $type;

			$ret = $model->save();
			return $ret;
		}
	}//}}}


	/* 
	 * 获取指定订单操作日志
	 * code INT  订单编号
	*/
	public function message($code, $type=1){//{{{
		$model = Logs::find()->where(['code'=>$code, 'type'=>$type])->all();

		return $model;
	}//}}}




}
